
var stompClient
var user=new Vue({
    el:"#staff_app",
    data:{
        areaList:{areaList:[],userList:[]},
        dict:[],
        time:{startTime:null,endTime:null},
        gps:10,
    },
    methods:{
        selectProjectList:function (data={parentId:0,type:0}) {
            $.ajax({
                type: "GET",
                url:  baseURL + 'xinpai/project/list',
                contentType: "application/json",
                data: data,
                success: function(r){
                    if(r.code === 0){
                        if(data.parentId>0){
                            user.areaList.areaList=r.list;
                        }
                    }else{
                        alert(r.msg);
                    }
                }
            });
        },
        selectDictList:function (name) {
            $.ajax({
                type: "GET",
                url:  baseURL + 'sys/dict/select',
                contentType: "application/json",
                data: {name},
                success: function(r){
                    if(r.code === 0){
                        user.dict=r.list;
                    }else{
                        alert(r.msg);
                    }
                }
            });
        },
        getUsersList(data){
            $.ajax({
                type: "GET",
                url:  baseURL + 'xinpai/users/select',
                contentType: "application/json",
                data: data,
                success: function(r){
                    if(r.code === 0){
                        user.areaList.userList=r.list;
                        user.$nextTick(function () {
                            $('.collapse').collapse('hide')
                        })
                    }else{
                        alert(r.msg);
                    }
                }
            });
        },
        show(imei){
            let startTime=$("#startTime").val();
            let endTime=$("#endTime").val();
            this.time={startTime,endTime}
            if(!isBlank(imei)&&!isBlank(startTime)&&!isBlank(endTime)){
                $.ajax({
                    type: "GET",
                    url:  baseURL + 'xinpai/userdata/select',
                    contentType: "application/json",
                    data:{imei,startTime,endTime},
                    success: function(r){
                        if(r.code === 0){
                            for (var j = 0; j < r.list.length; j++) {
                                var obj = r.list[j];
                                let extData={imei:obj.userId,type:obj.msgType,time:obj.dataTime,max:1}
                                if(j==(r.list.length-1)){
                                    extData={imei:obj.userId,type:obj.msgType,time:obj.dataTime,max:0}
                                }
                                let locat=JSON.parse(obj.dataContent);
                                let icon= "../../statics/img/maker_blue.png";
                                let maker= new AMap.Marker({
                                    position: [locat.x,locat.y],
                                    icon: icon,
                                    offset: new AMap.Pixel(-26, -26),
                                    extData:extData
                                });
                                if(j==(r.list.length-1)){
                                    maker.setIcon("../../statics/img/cleaner.png");
                                }
                                if(obj.msgType!=user.gps&&j!=(r.list.length-1)){
                                    maker.hide();
                                }
                                maker.on('mouseover',function(){
                                    console.log(this.getExtData());
                                    let obj=this.getExtData();
                                    let tick=obj.type==69?'(基站)':'(GPS)'
                                    this.setLabel({
                                        offset: new AMap.Pixel(-0, -20),
                                        content: obj.time+tick
                                    });
                                })
                                maker.on('mouseout',function(){
                                    this.setLabel({
                                        content: ""
                                    });
                                })
                                map.add(maker);
                            }
                            map.setFitView();
                        }else{
                            alert(r.msg);
                        }
                    }
                });
            }else{
                alert("请选择时间");
            }

        },
        checkMap(){
            let list=map.getAllOverlays('marker');
            list.forEach(function (obj) {
                if(obj.getExtData().type==69&&user.gps==69){
                    obj.show();
                }else if(user.gps==10&obj.getExtData().type==69&&obj.getExtData().max>0){
                    obj.hide();
                }
            })
        }
    },
    created:function() {
        let obj=GetRequest();
        let data={projectId:obj.pid,nexus:'true'};
        this.getUsersList(data);
        this.selectProjectList({parentId:GetRequest().pid,type:1});
        this.selectDictList("部门");

    }
})
/*
function connect() {
    const socket = new SockJS('/endpointSang');
    stompClient = Stomp.over(socket);
    stompClient.connect({}, function (frame) {
        let firmId=GetRequest().firmId;
        stompClient.subscribe(`/user/${firmId}/shouhuan`, function (response) {
            console.log(response);
            let devic =JSON.parse(response.body).user;
            let list=map.getAllOverlays('marker');
            list.forEach(function (obj) {
                if(obj.getExtData().imei==devic.imei&&devic.state==1){
                    var row=$("#jqGrid").jqGrid('getRowData',devic.imei);
                    row.state=1;
                    $("#jqGrid").jqGrid('getRowData',devic.imei);
                    $("#jqGrid").jqGrid('setRowData',devic.imei,row);
                    if(devic.location!=null){
                        var position=devic.location.split(",");
                        obj.moveTo(new AMap.LngLat(position[0], position[1]),4);
                    }
                }
            })

        });
    });

}

function disconnect() {
    if (stompClient != null) {
        stompClient.disconnect();
    }
}
connect();
*/
var map= new AMap.Map('mapcontainer', {
    resizeEnable: true, //是否监控地图容器尺寸变化
    zoom:11, //初始化地图层级
    center: [116.397428, 39.90923] //初始化地图中心点
});
